#自动查找头文件路径函数(没有去重)
macro(FIND_INCLUDE_DIR result curdir)  
    file(GLOB_RECURSE children "${curdir}/*.hpp" "${curdir}/*.h" )	
    # message(STATUS "children= ${children}")								
    set(dirlist "")														
    foreach(child ${children})											
        string(REGEX REPLACE "(.*)/.*" "\\1" LIB_NAME ${child})			
        if(IS_DIRECTORY ${LIB_NAME})									
            LIST(APPEND dirlist ${LIB_NAME})							
        endif()															
    endforeach()														
    set(${result} ${dirlist})											
endmacro()																

macro(FIND_SRC_INC_DIR src inc curdir) 
    FIND_INCLUDE_DIR(${inc} ${curdir})
    file(GLOB_RECURSE ${src} ${curdir}/*.c)
endmacro()

FIND_SRC_INC_DIR(PWM_SRC PWM_INC ${PROJECT_SOURCE_DIR}/pwm)	
FIND_SRC_INC_DIR(PIN_SRC PIN_INC ${PROJECT_SOURCE_DIR}/pin)	
FIND_SRC_INC_DIR(MOTOR_SRC MOTOR_INC ${PROJECT_SOURCE_DIR}/motor)	
FIND_SRC_INC_DIR(MODBUS_SLAVE_SRC MODBUS_SLAVE_INC ${PROJECT_SOURCE_DIR}/modbusSlave)	
FIND_SRC_INC_DIR(I2C_SRC I2C_INC ${PROJECT_SOURCE_DIR}/i2c)	
FIND_SRC_INC_DIR(FREEMODBUS_SRC FREEMODBUS_INC ${PROJECT_SOURCE_DIR}/freemodbus)	
FIND_SRC_INC_DIR(DELAY_SRC DELAY_INC ${PROJECT_SOURCE_DIR}/delay)
FIND_SRC_INC_DIR(ADC_SRC ADC_INC ${PROJECT_SOURCE_DIR}/adc)	
FIND_SRC_INC_DIR(DATA_SENSING_SRC DATA_SENSING_INC ${PROJECT_SOURCE_DIR}/dataSensing)	
FIND_SRC_INC_DIR(IQMATH_SRC IQMATH_INC ${PROJECT_SOURCE_DIR}/iqmath)	

set(Src main.c
    ${PWM_SRC}
    ${PIN_SRC}
    ${MOTOR_SRC}
    ${MODBUS_SLAVE_SRC}
    ${I2C_SRC}
    ${FREEMODBUS_SRC}
    ${DELAY_SRC}
    ${ADC_SRC}
    ${DATA_SENSING_SRC}
    ${IQMATH_SRC}
)

set_source_files_properties(${Src} PROPERTIES
    COMPILE_DEFINITIONS ESP_PLATFORM=1
)

set(Inc 
    ${PWM_INC}
    ${PIN_INC}
    ${MOTOR_INC}
    ${MODBUS_SLAVE_INC}
    ${I2C_INC}
    ${FREEMODBUS_INC}
    ${DELAY_INC}
    ${ADC_INC}
    ${DATA_SENSING_INC}
    ${IQMATH_INC}
)

# message(${Src})
# message(${Inc})